// JavaScript Document
window.onload=function() {
    // 搜索--------------------------------------------------------------
    var search_text = document.getElementById("search_text");
    search_text.onclick = function () {
        search_text.value = "";
    }
    document.addEventListener("click", function () {
        search_text.value = "卡通手机壳";
    }, true);
}
$(function(){
    var url="http://wthrcdn.etouch.cn/weather_mini?city=北京";
    function wea(d_url){
        $.getJSON(d_url,function(data){
            if(data.data.forecast[0].type=="晴"){
                $('.weather').find('i').html("<img src='images/day_qing.png'>")
            }else if(data.data.forecast[0].type=="多云"){
                $('.weather').find('i').html("<img src='images/day_duoyun.png'>")
            }else{
                $('.weather').find('i').html("<img src='images/day_yin.png'>")
            }

            $('.weather').find('p').eq(0).html("温度:"+data.data.wendu+"摄氏度/");
            $('.weather').find('p').eq(1).html(data.data.forecast[0].fengxiang);
        })
    }
    wea(url);
    $('.diqu').find('ul').each(function(){
        $(this).find('a').click(function(){
            var city=$(this).html();
            $(this).addClass('active').parent().siblings().find('a').removeClass('active');
            $('.diqu').find('a').eq(1).html(city);
            var url="http://wthrcdn.etouch.cn/weather_mini?city="+city;
            wea(url);
        })
    })
    //导航列表选项卡---------------------------------------------------------------
	var timer;
	$('#navList').find('li').each(function(index){
		$(this).hover(
			function(){
			clearInterval(timer);
			$(this).addClass('ac').siblings().removeClass('ac');
			$('.pop').css("display","block");
			$('.pop>div').eq(index).css("display","block").siblings().css("display","none")
			},
			function(){
			var nav_this=this;
			timer=setTimeout(function(){
				$('.pop').css("display","none");
				$(nav_this).removeClass('ac');
			},200)
		});
		$('.pop').hover(
			function(){
			clearInterval(timer)
			},
			function(){
			$('.pop').css("display","none");
			$('#navList').find('li').removeClass('ac');
		})
	});

//----------banner 轮播--------------------------------------------------------------------


            var i=0;
            var clone=$("#bannerA .num li").first().clone();
            $("#bannerA #bannerList").append(clone);
            var size=$("#bannerA #bannerList li");
            $("#bannerA .num li").first().addClass("col");
            //鼠标划入圆点
            $("#bannerA .num li").hover(function(){
                var index=$(this).index();
                i=index;
                $("#bannerA #bannerList").stop().animate({left:-index*730},600);
                $("#bannerA .num li").eq(index).addClass("col").siblings().removeClass("col");
            });
            //自动轮播
            var timer=setInterval(function(){
                l_move()
            },1000);
            //d对banner定时操作
            $("#bannerA").hover(function(){
                clearInterval(timer);
            },function(){
                timer=setInterval(function(){
                    l_move()
                },1000);
            });
            //向左按钮
            $("#bannerA #prevBtn").click(function(){
                l_move()
            });
            //向右按钮
            $("#bannerA #nextBtn").click(function(){
                r_move()
            });

            //向左按钮
            function l_move(){
                i++;
                //console.log(i)
                if(i==size.length-1){
                    $("#bannerA #bannerList").css({left:0});
                    i=0;
                }
                $("#bannerA #bannerList").stop().animate({left:-i*730},600);
                $("#bannerA .num li").eq(i).addClass("col").siblings().removeClass("col");
            }
            //向右按钮

            function r_move(){
                i--;
                if(i==-1){
                    $("#bannerA #bannerList").css({left:-(size-1)*730});
                    i=size-2;
                }
                $("#bannerA #bannerList").stop().animate({left:-i*730},600);
                $("#bannerA .num li").eq(0).addClass("col").siblings().removeClass("col");
            }

///*选项卡---------------------------------------------------------------------------

	$(".title").each(function(){

        $(this).find('li').each(function(index){
            $(this).mouseenter(function(){
                $(this).addClass('ac').siblings().removeClass('ac');
                $(this).parents().siblings('.con').find('.details').eq(index).show().siblings(".details").hide();
            })
        })
    });

//侧边导航----------------------------------------------------------------------------------------------

	var json1=["服饰","美妆","手机","家电","数码","运动","居家","母婴","食品","图书","车品","服务"];
	var json2=["1F","2F","3F","4F","5F","6F","7F","8F","9F","10F","11F","12F"];
	$(".subnav").find('li').each(function(index){
		$(this).click(function(e){
			e.preventDefault();
			$(this).addClass('ac').siblings().removeClass('ac');
			$(".subnav").find('li').each(function(index){
				$(this).html(json2[index]);
			});
			$(this).html(json1[index]);
			$("html,body").animate(
				{scrollTop:$(".floorF").eq(index).offset().top},1000
			)
		})
	});
	$(window).on("scroll",function(){
		var last=-1;
		if($(window).scrollTop()>1400){
			$(".subnav").show();
			$(".floorF").each(function(){
				if($(this).offset().top<$(window).scrollTop()+400){//400为接近屏幕的敏感区
					last++;
				}
			});
			$(".subnav").find('li').each(function(index){
				$(this).html(json2[index]);
			});
			$(".subnav").find('li').eq(last).html(json1[last]).addClass('ac').siblings().removeClass('ac');
		}else {
			$(".subnav").hide();
		}
	});
});

	
	//找到楼层列表中的每一个li，和每一个楼层
	/*var oFloorList=document.getElementsByClassName('floorList')[0];
	//var aLi=oFloorList.children;
	var aFloor=document.getElementsByClassName('floorF');
	var arr=[];
	
	//-------------------------------------------------
	for(var i=0; i<aFloor.length; i++){
		var json={};
		json.name=i;
		json.offsetTop=aFloor[i].offsetTop;
		arr.push(json);
	};
	
	window.onscroll=function(ev){
		//ev=ev || window.event;
		//当滚条高度加屏幕高度等于1730时让floorlist显示---------------------------------------------------------
		var scrolltop=document.documentElement.scrollTop || document.body.scrollTop;//获取滚动条高度
		//console.log(scrolltop)
		var h=document.documentElement.clientHeight;//获取浏览器高度
		//console.log(h)
		if(scrolltop+h>1730){
			oFloorList.style.display='block';
		}else{
			oFloorList.style.display='none';
		};
		if(scrolltop>aFloor[aFloor.length-1].offsetTop+aFloor[aFloor.length-1].offsetHeight){
			oFloorList.style.display='none';
		};
		
		// 根据楼层滚动位置，定位编号------------------------------------------------
		var last_arr=[];
		
		for(var j=0; j<arr.length; j++){
			if(arr[j].offsetTop<scrolltop+h/2){
				last_arr.push(arr[j].name);
			}
		};
		
		//console.log(last_arr)
		if (scrolltop>1730) {
            var li_index = last_arr[last_arr.length - 1];
	
			for(var l=0; l<aFloor.length; l++){
				aLi[l].className='';
			};
			aLi[li_index].className='ac';
		};
		
		

	};

	//点击编号，跳转到相对楼层-----------------------------------------------
	for(var i=0; i<aFloor.length; i++){
		aLi[i].index=i;
		aLi[i].onclick=function(){
			var start=document.documentElement.scrollTop || document.body.scrollTop;
			var end=arr[this.index].offsetTop;
			move(start,end)
		}
	};
	//move-------------------------------------------------------
	var timer;
	function move(start,end){
		var dis=end-start;
		var count=parseInt(1500/30);
		var n=0;
		clearInterval(timer);
		timer=setInterval(function(){
			n++;
			var a=1-n/count;
			var step_dis=start+dis*(1-a*a*a*a);
			window.scrollTo(0,step_dis);
			if(n==count){
				clearInterval(timer);
			};
		},30)*/
	
